/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include ".\mimicinfo.h"

//---------------------------------------------------------------------------

MimicInfo::MimicInfo(void)
{
	Initialize();
}

MimicInfo::~MimicInfo(void)
{
}

//---------------------------------------------------------------------------

MimicInfo& MimicInfo::operator = (MimicInfo& miIn)
{
	mimicName    = miIn.mimicName;
	mimicOS      = miIn.mimicOS;

	bTosIcmp     = miIn.bTosIcmp;
	bTosTcp      = miIn.bTosTcp;
	bTosUdp      = miIn.bTosUdp;

	wIpIdIcmp    = miIn.wIpIdIcmp;
	wIpIdTcp     = miIn.wIpIdTcp;
	wIpIdUdp     = miIn.wIpIdUdp;

	wFragOffIcmp = miIn.wFragOffIcmp;
	wFragOffTcp  = miIn.wFragOffTcp;
	wFragOffUdp  = miIn.wFragOffUdp;

	bTTLIcmp     = miIn.bTTLIcmp;
	bTTLTcp      = miIn.bTTLTcp;
	bTTLUdp      = miIn.bTTLUdp;

	wIcmpId      = miIn.wIcmpId;
	wIcmpSeq     = miIn.wIcmpSeq;

	srcPort      = miIn.srcPort;

	wWindow      = miIn.wWindow;

	wTransId     = miIn.wTransId;

	bTrafficClass6 = miIn.bTrafficClass6;
	dwFlowLabel6   = miIn.dwFlowLabel6;
	bHopLimit6_Gen = miIn.bHopLimit6_Gen;
	bHopLimit6_MLD = miIn.bHopLimit6_MLD;
	bHopLimit6_ND  = miIn.bHopLimit6_ND;

	wIcmpId6       = miIn.wIcmpId6;
	wIcmpSeq6      = miIn.wIcmpSeq6;
	wWindow6       = miIn.wWindow6;

	return (*this);
}

//---------------------------------------------------------------------------

void MimicInfo::Initialize(void)
{
	Set(__mosRandom);
}

//---------------------------------------------------------------------------

void MimicInfo::LoadFromPointer(MimicInfo* miIn)
{
	if(miIn==NULL){
		Initialize();
		return;
	}

	mimicName    = miIn->mimicName;
	mimicOS      = miIn->mimicOS;

	bTosIcmp     = miIn->bTosIcmp;
	bTosTcp      = miIn->bTosTcp;
	bTosUdp      = miIn->bTosUdp;

	wIpIdIcmp    = miIn->wIpIdIcmp;
	wIpIdTcp     = miIn->wIpIdTcp;
	wIpIdUdp     = miIn->wIpIdUdp;

	wFragOffIcmp = miIn->wFragOffIcmp;
	wFragOffTcp  = miIn->wFragOffTcp;
	wFragOffUdp  = miIn->wFragOffUdp;

	bTTLIcmp     = miIn->bTTLIcmp;
	bTTLTcp      = miIn->bTTLTcp;
	bTTLUdp      = miIn->bTTLUdp;

	wIcmpId      = miIn->wIcmpId;
	wIcmpSeq     = miIn->wIcmpSeq;

	srcPort      = miIn->srcPort;

	wWindow      = miIn->wWindow;

	wTransId     = miIn->wTransId;

	bTrafficClass6 = miIn->bTrafficClass6;
	dwFlowLabel6   = miIn->dwFlowLabel6;
	bHopLimit6_Gen = miIn->bHopLimit6_Gen;
	bHopLimit6_MLD = miIn->bHopLimit6_MLD;
	bHopLimit6_ND  = miIn->bHopLimit6_ND;

	wIcmpId6       = miIn->wIcmpId6;
	wIcmpSeq6      = miIn->wIcmpSeq6;
	wWindow6       = miIn->wWindow6;
}

//---------------------------------------------------------------------------

bool MimicInfo::Set(MimicOS mos)
{
	mimicOS = mos;

	switch(mos){
		case __mosRandom :
			// TODO random here SHOULD be also random for TOS, FragOff, TTL and Window
			mimicName    = _T("- random -");
			bTosIcmp     = 0x00;
			bTosTcp      = 0x00;
			bTosUdp      = 0x00;
			wIpIdIcmp    = MIMIC_INC_TYPE_R;
			wIpIdTcp     = MIMIC_INC_TYPE_R;
			wIpIdUdp     = MIMIC_INC_TYPE_R;
			wFragOffIcmp = 0x0000;
			wFragOffTcp  = 0x4000;
			wFragOffUdp  = 0x0000;
			bTTLIcmp     = 0x80;
			bTTLTcp      = 0x80;
			bTTLUdp      = 0x80;
			wIcmpId      = MIMIC_INC_TYPE_R;
			wIcmpSeq     = MIMIC_INC_TYPE_R;
			srcPort      = 0x0404;
			wWindow      = 0xFFFF;
			wTransId     = MIMIC_INC_TYPE_R;

			bTrafficClass6 = 0x00;
			dwFlowLabel6   = 0x00000000;
			bHopLimit6_Gen = 0x80;
			bHopLimit6_MLD = 0x01;
			bHopLimit6_ND  = 0xFF;
			wIcmpId6       = 0x0000;
			wIcmpSeq6      = MIMIC_INC_TYPE_R;
			wWindow6       = 0x4000;

			bMaxResponseTime = 100;
			return true;

		case __mosWindowsXPSP2 :
			mimicName    = _T("Windows XP SP2");
			bTosIcmp     = 0x00;
			bTosTcp      = 0x00;
			bTosUdp      = 0x00;
			wIpIdIcmp    = MIMIC_INC_TYPE_RS1;
			wIpIdTcp     = MIMIC_INC_TYPE_RS1;
			wIpIdUdp     = MIMIC_INC_TYPE_RS1;
			wFragOffIcmp = 0x0000;
			wFragOffTcp  = 0x4000;
			wFragOffUdp  = 0x0000;
			bTTLIcmp     = 0x80;
			bTTLTcp      = 0x80;
			bTTLUdp      = 0x80;
			wIcmpId      = 0x0200;
			wIcmpSeq     = MIMIC_INC_TYPE_R1S;
			srcPort      = 0x0404;
			wWindow      = 0xFFFF;
			wTransId     = MIMIC_INC_TYPE_R;

			bTrafficClass6 = 0x00;
			dwFlowLabel6   = 0x00000000;
			bHopLimit6_Gen = 0x80;
			bHopLimit6_MLD = 0x01;
			bHopLimit6_ND  = 0xFF;
			wIcmpId6       = 0x0000;
			wIcmpSeq6      = MIMIC_INC_TYPE_R1;
			wWindow6       = 0x4000;

			bMaxResponseTime = 100;
			return true;

		case __mosWindows2K3 :
			mimicName    = _T("Windows Server 2003");
			bTosIcmp     = 0x00;
			bTosTcp      = 0x00;
			bTosUdp      = 0x00;
			wIpIdIcmp    = MIMIC_INC_TYPE_R;
			wIpIdTcp     = MIMIC_INC_TYPE_R;
			wIpIdUdp     = MIMIC_INC_TYPE_R;
			wFragOffIcmp = 0x0000;
			wFragOffTcp  = 0x0000;
			wFragOffUdp  = 0x0000;
			bTTLIcmp     = 0x80;
			bTTLTcp      = 0x80;
			bTTLUdp      = 0x80;
			wIcmpId      = 0x300;
			wIcmpSeq     = MIMIC_INC_TYPE_R1S;
			srcPort      = 0x0404;		// presupun !
			wWindow      = 0x4000;
			wTransId     = 0x0001;

			bTrafficClass6 = 0x00;
			dwFlowLabel6   = 0x00000000;
			bHopLimit6_Gen = 0x80;
			bHopLimit6_MLD = 0x01;
			bHopLimit6_ND  = 0xFF;
			wIcmpId6       = 0x0000;
			wIcmpSeq6      = MIMIC_INC_TYPE_R1;
			wWindow6       = 0x4000;

			bMaxResponseTime = 100;
			return true;

		case __mosLinux_2_4 :
			mimicName    = _T("Linux kernel 2.4");
			bTosIcmp     = 0x00;
			bTosTcp      = 0x10;
			bTosUdp      = 0x00;
			wIpIdIcmp    = 0x0000;
			wIpIdTcp     = MIMIC_INC_TYPE_R;
			wIpIdUdp     = MIMIC_INC_TYPE_R;
			wFragOffIcmp = 0x4000;
			wFragOffTcp  = 0x4000;
			wFragOffUdp  = 0x4000;
			bTTLIcmp     = 0x40;
			bTTLTcp      = 0x40;
			bTTLUdp      = 0x40;
			wIcmpId      = MIMIC_INC_TYPE_R1S;
			wIcmpSeq     = 0x0001;
			srcPort      = 0x8000;
			wWindow      = 0x16D0;
			wTransId     = MIMIC_INC_TYPE_R;

			bTrafficClass6 = 0x00;
			dwFlowLabel6   = 0x00000000;
			bHopLimit6_Gen = 0x40;
			bHopLimit6_MLD = 0x01;
			bHopLimit6_ND  = 0xFF;
			wIcmpId6       = MIMIC_INC_TYPE_R;
			wIcmpSeq6      = 0x0000;
			wWindow6       = 0x1680;

			bMaxResponseTime = 100;
			return true;

		case __mosLinux_2_6 :
			mimicName    = _T("Linux kernel 2.6");
			bTosIcmp     = 0x00;
			bTosTcp      = 0x10;
			bTosUdp      = 0x00;
			wIpIdIcmp    = 0x0000;
			wIpIdTcp     = MIMIC_INC_TYPE_R;
			wIpIdUdp     = MIMIC_INC_TYPE_R;
			wFragOffIcmp = 0x4000;
			wFragOffTcp  = 0x4000;
			wFragOffUdp  = 0x4000;
			bTTLIcmp     = 0x40;
			bTTLTcp      = 0x40;
			bTTLUdp      = 0x40;
			wIcmpId      = MIMIC_INC_TYPE_R3S;
			wIcmpSeq     = 0x0000;
			srcPort      = 0x8000;
			wWindow      = 0x16D0;
			wTransId     = MIMIC_INC_TYPE_R;

			bTrafficClass6 = 0x00;
			dwFlowLabel6   = 0x00000000;
			bHopLimit6_Gen = 0x40;
			bHopLimit6_MLD = 0x01;
			bHopLimit6_ND  = 0xFF;
			wIcmpId6       = MIMIC_INC_TYPE_R;
			wIcmpSeq6      = 0x0000;
			wWindow6       = 0x1680;

			bMaxResponseTime = 100;
			return true;

		case __mosSolaris_8 :
			mimicName    = _T("Sun Solaris 8");
			bTosIcmp     = 0x00;
			bTosTcp      = 0x00;
			bTosUdp      = 0x00;
			wIpIdIcmp    = MIMIC_INC_TYPE_R5;
			wIpIdTcp     = MIMIC_INC_TYPE_R;
			wIpIdUdp     = MIMIC_INC_TYPE_R1;
			wFragOffIcmp = 0x4000;
			wFragOffTcp  = 0x4000;
			wFragOffUdp  = 0x4000;
			bTTLIcmp     = 0xFE;
			bTTLTcp      = 0x3F;
			bTTLUdp      = 0xFE;
			wIcmpId      = MIMIC_INC_TYPE_R1;
			wIcmpSeq     = 0x0000;
			srcPort      = 0x8000; // presupun
			wWindow      = 0x60F4;
			wTransId     = MIMIC_INC_TYPE_R1;

			bTrafficClass6 = 0x00;
			dwFlowLabel6   = 0x00000000;
			bHopLimit6_Gen = 0x80;
			bHopLimit6_MLD = 0x01;
			bHopLimit6_ND  = 0xFF;
			wIcmpId6       = 0x0000;
			wIcmpSeq6      = MIMIC_INC_TYPE_R;
			wWindow6       = 0x4000;

			bMaxResponseTime = 100;
			return true;

		case __mosNevada35 :
			mimicName    = _T("Open Solaris (nv35)");
			bTosIcmp     = 0x00;
			bTosTcp      = 0x00;
			bTosUdp      = 0x00;
			wIpIdIcmp    = MIMIC_INC_TYPE_RS1;
			wIpIdTcp     = MIMIC_INC_TYPE_RS1;
			wIpIdUdp     = MIMIC_INC_TYPE_RS1;
			wFragOffIcmp = 0x0000;
			wFragOffTcp  = 0x4000;
			wFragOffUdp  = 0x4000;
			bTTLIcmp     = 0xFF;
			bTTLTcp      = 0x40;
			bTTLUdp      = 0x40;
			wIcmpId      = MIMIC_INC_TYPE_R1;
			wIcmpSeq     = 0x0000;
			srcPort      = MIMIC_INC_TYPE_R;
			wWindow      = 0xc1e8;
			wTransId     = MIMIC_INC_TYPE_R;

			bTrafficClass6 = 0x00;
			dwFlowLabel6   = 0x00000000;
			bHopLimit6_Gen = 0x3C;
			bHopLimit6_MLD = 0x01;
			bHopLimit6_ND  = 0xFF;
			wIcmpId6       = MIMIC_INC_TYPE_R1;
			wIcmpSeq6      = 0x0000;
			wWindow6       = 0xc4e0;

			bMaxResponseTime = 100;
			return true;

		default:
			return false;
	}
}

//---------------------------------------------------------------------------
